package com.lxmes.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.sales.domain.ZcSupplierQuotation;
import com.lxmes.sales.service.IZcSupplierQuotationService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 供方报价Controller
 * 
 * @author lx
 * @date 2023-06-21
 */
@Api(tags = "供方报价")    
@RestController
@RequestMapping("/sales/ZcSupplierQuotation")
public class ZcSupplierQuotationController extends BaseController
{
    @Autowired
    private IZcSupplierQuotationService zcSupplierQuotationService;

    /**
     * 查询供方报价列表
     */
    @ApiOperation("查询供方报价列表")
    @PreAuthorize("@ss.hasPermi('sales:ZcSupplierQuotation:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZcSupplierQuotation zcSupplierQuotation)
    {
        startPage();
        List<ZcSupplierQuotation> list = zcSupplierQuotationService.selectZcSupplierQuotationList(zcSupplierQuotation);
        return getDataTable(list);
    }

    /**
     * 导出供方报价列表
     */
    @ApiOperation("导出供方报价列表")
    @PreAuthorize("@ss.hasPermi('sales:ZcSupplierQuotation:export')")
    @Log(title = "供方报价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZcSupplierQuotation zcSupplierQuotation)
    {
        List<ZcSupplierQuotation> list = zcSupplierQuotationService.selectZcSupplierQuotationList(zcSupplierQuotation);
        ExcelUtil<ZcSupplierQuotation> util = new ExcelUtil<ZcSupplierQuotation>(ZcSupplierQuotation.class);
        util.exportExcel(response, list, "供方报价数据");
    }

    /**
     * 获取供方报价详细信息
     */
    @ApiOperation("获取供方报价详细信息")
    @PreAuthorize("@ss.hasPermi('sales:ZcSupplierQuotation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zcSupplierQuotationService.selectZcSupplierQuotationById(id));
    }

    /**
     * 新增供方报价
     */
    @ApiOperation("新增供方报价")
    @PreAuthorize("@ss.hasPermi('sales:ZcSupplierQuotation:add')")
    @Log(title = "供方报价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZcSupplierQuotation zcSupplierQuotation)
    {
        return toAjax(zcSupplierQuotationService.insertZcSupplierQuotation(zcSupplierQuotation));
    }

    /**
     * 报价确认
     */
    @ApiOperation("报价确认")
    @PostMapping("confirm")
    public AjaxResult confirm(@RequestBody ZcSupplierQuotation zcSupplierQuotation)
    {
        return toAjax(zcSupplierQuotationService.confirm(zcSupplierQuotation));
    }

    /**
     * 修改供方报价
     */
    @ApiOperation("修改供方报价")
    @PreAuthorize("@ss.hasPermi('sales:ZcSupplierQuotation:edit')")
    @Log(title = "供方报价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZcSupplierQuotation zcSupplierQuotation)
    {
        return toAjax(zcSupplierQuotationService.updateZcSupplierQuotation(zcSupplierQuotation));
    }

    /**
     * 删除供方报价
     */
    @ApiOperation("删除供方报价")
    @PreAuthorize("@ss.hasPermi('sales:ZcSupplierQuotation:remove')")
    @Log(title = "供方报价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zcSupplierQuotationService.deleteZcSupplierQuotationByIds(ids));
    }
    /**
     * 导入供方报价
     */
    @Log(title = "供方报价", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<ZcSupplierQuotation> util = new ExcelUtil<>(ZcSupplierQuotation.class);
        List<ZcSupplierQuotation> zcSupplierQuotationList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = zcSupplierQuotationService.imporIteminfo(zcSupplierQuotationList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<ZcSupplierQuotation> util = new ExcelUtil<>(ZcSupplierQuotation.class);
        util.importTemplateExcel(response,"供方报价");
    }
}
